// pages/IntelligentRecognition/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recognitionType:"",//0出库1入库
    showIn:true,
    showPy:true,
    income:0,
    paid:0,
    page:0,
    size:10,
    totalPage: 0, // 总页数
    pullFlag: false, // 是否向上拉动到底部
	  tableList: [1,2],
	  listTip: '上拉加载更多'
  },
// 获取列表数据
getList(){
  let that=this
  // 获取流水清单列表
  wx.$req({
    url: '/wms/ai/list?page='+this.data.page+'&size='+this.data.size,
    method:'POST',
    data: {recognitionType:that.data.recognitionType},
    loadingText: '加载中...'
  }).then(res => {
      let tableList=res.data.content
      let totalPage = Math.ceil(res.data.totalElements / 10)
      let rows = this.data.tableList
      if (totalPage == 1 || this.data.totalPage === totalPage ) {
        this.setData({ listTip: '暂无更多' })
      } else {
        this.setData({ listTip: '上拉加载更多' })
      }
      if (totalPage == 0) {
        this.setData({ listTip: '暂无内容' })
      }
       // 列表数据：为true 则需要push, false，则直接覆盖
    if (this.data.pullFlag) {
      rows.push(...res.data.content)
    } else {
      rows = res.data.content
    }
      that.setData({
        tableList: rows 
      })

    }).finally(() => { wx.stopPullDownRefresh() })
},
// 获取统计数据
getStatic(){
  let that=this
  // 获取流水统计数据
  wx.$req({
    url: '/wms/ai/statistics',
    method:'POST',
    loadingText: '加载中...'
  }).then(res => {
      let income=res.data.into
      let paid=res.data.out
      that.setData({
        income:income/1000,
        paid:paid/1000
      })
  })
},
// 更改类型
onChange(e){
  let type=e.detail.name
  let showIn=true,showPy=true
  if(type=="0"){//支出
    showIn=false,
    showPy=true
  }else if(type=="1"){//收入
    showIn=true,
    showPy=false
  }else{//全部
    showIn=true,
    showPy=true,
    type=""
  }
  this.setData({ 
    pullFlag: false,
    page: 0,
    size: 10,
    showIn:showIn,
    showPy:showPy,
    recognitionType:type
  })
  console.log("in:"+this.data.showIn+"  out:"+this.data.showPy)
  this.getList()
    this.getStatic()
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getList()
    this.getStatic()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({ 
      pullFlag: false,
      page: 0,
      size: 10
		})
    this.getList()
    this.getStatic()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let  pageNum=this.data.page
    let  pageSize=this.data.size
    if (pageNum < this.data.totalPage) {
      pageNum += 1
      this.setData({  
        pullFlag: true,
        page: pageNum,
        size: pageSize
      })
      this.getList()
    }
  },
  toDetail () {
    wx.navigateTo({
      url: '/pages/myLeaseDetail/index',
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})